"""
Copyright 2007, Thomas Dejanovic.
 
This is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this software; if not, write to the Free
Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA, or see the FSF site: http://www.fsf.org.

Module for all Register and related leaf-type (childless) hatch nodes.
"""

id = "$Id: hatch_register.py 667 2010-07-01 00:12:17Z jayshurtz $"
# $URL: http://hatch.googlecode.com/svn/tags/taggle_release_3.0/hatch/hatch_nodes/hatch_register.py $
# $Author: jayshurtz $
version = " version ".join(id.split()[1:3])


import to_hatch_structure
from hatch_node_physical import *
from hatch_constants import DEFAULT_VALUE, BIT_WIDTH

DEFAULT_REG_WIDTH = 1   # TODO Move these to hatch_constants ?
DEFAULT_REG_VALUE = 0

class Register(HatchNodePhysical):
    """ A stand alone register or field inside a register pack.
        As the lowest leaf in the hierachy, a register's 'hatch_leaf' 
        property should be 'True' to indicate that the register should have no 
        children.
    """
    def __init__(self, name, **properties):    # Does not allow passing in of child nodes with *args.
        """ """
        HatchNodePhysical.__init__(self, name, hatch_leaf=True, **properties)    # Python will complain if 'hatch_leaf' is already in **properties.
        self.properties[BIT_WIDTH] = self.properties.get(BIT_WIDTH, DEFAULT_REG_WIDTH)  # Set default if it doesn't exist.

        # self.properties[DEFAULT_VALUE] = int(round(self.properties.get(DEFAULT_VALUE, DEFAULT_REG_VALUE)))
        self.properties[DEFAULT_VALUE]   = self.properties.get(DEFAULT_VALUE, DEFAULT_REG_VALUE)

# Main for testing.
if __name__ == "__main__":

    r = Register('Robin', bit_width=8)
    #r = Register('Robin', bit_width=8, hatch_leaf=False)
    print r.info()


